Embodiments of the present invention generally relate to a database management system, and more specifically, to a method and system for database query.
A database is a warehouse for organizing, storing and managing data according to a structure of the data. A relational database is a currently common type of database where data in a relational database are currently queried using the Structured Query Language (SQL) whose functions include query, manipulation, definition, and control. SQL is a comprehensive, general-purpose relational database language and also a highly non-procedural language. That is, SQL only requires users to indicate what to do, without indicating how to do the operation. SQL integrates all operations during a database lifecycle. Moreover, SQL provides methods of interacting with a relational database and can co-work with standard programming languages.
A database management system (referred as “DBMS” for short) is a large software suite for establishing, using, manipulating and managing databases. A database management system manages and controls databases in a unified manner, so as to ensure safety and integrity of databases. Existing relational database management systems include SQL Server, Sybase, Informix, Oracle, DB2 available from International Business Machines (IBM) Corporation, etc. All query engines (also known as Query Execution Runtime) of a database management system support the query function using SQL. A user or an application may use SQL to query a managed database by a query engine of a database management system. A result of the query usually includes a plurality of records. The time elapsed before the first item of data conforming to the query condition is returned is usually referred to as the query response time, and the time elapsed before a set of all data results conforming to the query condition is returned is referred to as a query total time.
Upon receipt of a query request, as far as possible, a current database management system may use minimum total time for query by default, and will generate a query access plan that can return complete query results in the most efficient way to the user or the application issuing the query. Sometimes, the user or application issuing the query tends to obtain the first several query results as soon as possible, without caring about the time elapsing during the entire query. Such an application may use the statement “OPTIMIZED FOR FIRST N ROW” to notify a query engine optimizer of the database management system to execute the query in minimum query response time instead of minimum query total time.
However, many applications need to execute a query in both minimum query response time and minimum query total time. For example, when an application issuing a query makes a query request, the application may need to obtain a response from a database as soon as possible and then obtain several initial query results so that the application can judge whether or not to execute a subsequent query or other business logics. Current database management systems can only provide query plans in minimum query response time or provide query plans in minimum query total time, whereas none of these query plans can reduce both the query response time and the query total time.